--[[/**
-- * 
 * 露夫每对敌人造成自身[0]%攻击的伤害，增加[1]buff
-- *
-- */]]

---@class BuffEffect515100 : BaseBuffEffect
BuffEffect515100 = ClientFight.CreateClass("BuffEffect515100", ClientFight.BaseBuffEffect)
local t = BuffEffect515100
t.BUFF_EFFECT_515100_ATTACK = "BUFF_EFFECT_515100_ATTACK";
t.BUFF_EFFECT_515100_DAMAGE = "BUFF_EFFECT_515100_DAMAGE";
---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local parameters = {...};
    local result = parameters[3];
    if (AttackUtils.isDamage(result.state) and result.damage > 0) then
    local fighter = buff.target;
    local effectVal = buff.buffBean.f_BuffEffectValue;

    local oldDamageTotal = buff.effectParams[t.BUFF_EFFECT_515100_DAMAGE] or 0;
    local atk =  buff.effectParams[t.BUFF_EFFECT_515100_ATTACK] or 0;
    local newDamageTotal = oldDamageTotal + result.damage;
    buff.effectParams[t.BUFF_EFFECT_515100_DAMAGE] =  newDamageTotal;

    local finalNewDamageTotal = newDamageTotal;
        SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 触发 当前累计伤害:" .. finalNewDamageTotal);

    if (newDamageTotal < atk * Utils.toRatio(effectVal[1])) then
        return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

    end
    local buffOverlay =  (newDamageTotal / (atk * Utils.toRatio(effectVal[1]) * 1));
    newDamageTotal =  (newDamageTotal - buffOverlay * atk * Utils.toRatio(effectVal[1]));
    buff.effectParams[t.BUFF_EFFECT_515100_DAMAGE] =  newDamageTotal;

    local finalNewDamageTotal1 = newDamageTotal;
        SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
    .. buff.modelId .. " 触发 层数:" .. buffOverlay .. " 当前累计伤害:" .. finalNewDamageTotal1);

    BuffManager.addBuff(fight, buff.skill, buff.source, fighter, true, effectVal[2], buffOverlay, buff.addParameters);
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

end

function t:add( fight, buff)
    local fighter = buff.target;
    local atk = FighterAttributeManager.getFightAttr(fighter, FighterAttributeEnum.ATK);
    buff.effectParams[t.BUFF_EFFECT_515100_ATTACK] = atk;
    return ClientFight.BaseBuffEffect.add(self, fight, buff);

    end
t.New()